const mounted = (el, binding: any) => {
    const handler = (e) => {
        // 检测绑定dom是否包含点击元素,不包含触发传入的方法
        if (!el.contains(e.target)) {
            binding.value();
        }
        // 存储方法用来在指令卸载后，移除全局绑定事件
        el._clickOutSide = handler;
    };
    window.addEventListener('click', handler);
};
const unmounted = (el) => {
    // 移除全局绑定事件，用el._clickOutSide变量保证两次存储的内存地址相同
    window.removeEventListener('click', el._clickOutSide);
    delete el._clickOutSide;
};
const vClickOutSide = {
    mounted,
    unmounted
};
export const setupClickOutSideDirective = (app: any) => {
    app.directive('clickOutSide', vClickOutSide);
};
